﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Arc.DairyMan.DairyMan.DataAccess;
using Arc.DairyMan.DairyMan.Model;

namespace Arc.DairyMan.DairyMan.BusinessLogic
{
    public class blSabhasadTransactions : AbsBl
    {
        public blSabhasadTransactions()
        {
            ModelObj = new SabhasadTransactions();
            Dal = new dalSabhasadTransactions();
            Dal.ModelObj = ModelObj;
        }

        public override void Validation()
        {
            //MilkCollection _Model = (MilkCollection)ModelObj;
            //if (_Model.Date > DateTime.Now.Date)
            //    throw new Exception("Date cannot be future date.");
            //if (_Model.SabhasadId == 0)
            //    throw new Exception("Please select an existing Sabhasad Code.");
            //if (_Model.Quantity == 0)
            //    throw new Exception("Liter cannot be 0.");
            //if (_Model.Fat == 0)
            //    throw new Exception("Fat cannot be 0.");
            //if (_Model.Rate == 0)
            //    throw new Exception("Rate cannot be 0.");
        }

        public override void Search(string Critiera)
        {
            try
            {
                Dal.Search(Critiera, DS);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override void Select(string Critiera)
        {
            try
            {
                Dal.Select(Critiera, DS);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public override int Transaction(bool TransactionStarter)
        {
            try
            {
                Result = 0;
                Dal.BeginTransaction(TransactionStarter);
                if (ModelObj.TransactionMode == Common.TransactionModes.Delete)
                {
                    //ClassList = new ArrayList();
                    //ClassList.Add("contact_license");
                    //clsConnection.FindData(_ModelObj.Database, _ModelObj.FriendlyName, "Contact_ID", _ModelObj.Contact_ID.ToString(), ClassList);
                }
                else
                {
                    Validation();
                }

                Dal.ModelObj = ModelObj;
                Result = Dal.Transaction();

                Dal.CommitTransaction(TransactionStarter);
                return Result;
            }
            catch (Exception ex)
            {
                Dal.RollbackTransaction(TransactionStarter);
                throw ex;
            }
        }
    }
}
